package net.xiaoyu233.mitemod.miteite.item;

import net.minecraft.*;

public class FlintPickaxe extends ItemPickaxe {
    public FlintPickaxe(int par1, Material material) {
        super(par1, material);

    }

    @Override
    public int getHeatLevel(ItemStack item_stack) {
        return 1;
    }

    @Override
    public boolean canBlock() {
        return true;
    }

    @Override
    public float getStrVsBlock(Block block, int metadata, ItemStack itemStack, EntityPlayer player) {
        // 明确指定对哪些方块材料或特定方块有效
        if (block != null) {
            // 1. 通过方块材料判断：石头、矿石、铁砧等通常需要镐子挖掘的方块
            // 2. 或者通过具体的方块实例来判断（更直接）
            if (block == Block.cobblestone ||
                    block == Block.stone ||
                    block == Block.oreCoal ||
                    block == Block.oreIron ||
                    block == Block.oreGold ||
                    block == Block.oreRedstone ||
                    block == Block.oreLapis ||
                    block == Block.oreNetherQuartz) {
                return this.getMultipliedHarvestEfficiency(block)* 0.7F; // 使用燧石镐的基础效率
            }
        }
        // 对于其他方块，调用父类方法或返回一个基本值（如1.0F用于徒手，0.5F用于表示慢速）
        return super.getStrVsBlock(block, metadata, itemStack, player); // 或者返回 1.0F
    }

    @Override
    public boolean isRepairable() {
        return true;
    }

    @Override
    public boolean onBlockDestroyed(BlockBreakInfo info) {
        if (info.world.isRemote) {
            Minecraft.setErrorMessage("ItemTool.onBlockDestroyed: called on client?");
        }

        Block block = info.block;
        ItemStack item_stack = info.getHarvesterItemStack();
        if ((!(block instanceof BlockOre) || info.getMetadata() != 1) && block != Block.oreDiamond && block != Block.oreCoal && block != Block.oreEmerald && block != Block.oreRedstone && block != Block.oreLapis && block != Block.oreNetherQuartz) {
            float expReward = ToolModifierTypes.GEOLOGY.getModifierValue(info.getHarvesterItemStack().getTagCompound());
            if (expReward != 0.0F) {
                ItemStack dropItemStack = new ItemStack(info.block);
                ItemStack smeltingResult = RecipesFurnace.smelting().getSmeltingResult(dropItemStack, 5);
                if (smeltingResult != null) {
                    info.world.spawnEntityInWorld(new EntityExperienceOrb(info.world, (double)info.drop_x, (double)info.drop_y + (double)0.5F, (double)info.drop_z, (int)((float)smeltingResult.getExperienceReward() * expReward)));
                }
            }
        }

        if (item_stack.isItemStackDamageable() && !block.isPortable(info.world, info.getHarvester(), info.x, info.y, info.z) && !info.isResponsiblePlayerInCreativeMode() && info.getBlockHardness() >= 0.0F && this.getStrVsBlock(block, info.getMetadata()) >= 0.0F) {
            if (!(item_stack.getItem() instanceof ItemSword) && this.isEffectiveAgainstBlock(info.block, info.getMetadata()) && !item_stack.getItem().isMaxToolLevel(item_stack)) {
                this.addExpForTool(info.getHarvesterItemStack(), info.getResponsiblePlayer(), this.getExpForBlockBreak(info));
            }

            info.getHarvesterItemStack().tryDamageItem(DamageSource.generic, 120, info.getHarvester());
            return true;
        } else {
            return false;
        }
    }
}
